﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EQ1.Elements;
using com.woodsoft.core;
using EQ1.Templates;
using com.woodsoft.core.Files;
using EQ1.Objects;

namespace EQ1.Controls {
  public class SpellGem:Control, IUIElement<SpellGem> {
    public SpellGem ( UIDocument doc , string name ) : base( doc , name ) {
      this.SpellIconOffsetX = 0;
      this.SpellIconOffsetY = 0;
    }
    public SpellGem ( UIDocument doc ) : this( doc , "SpellGem" ) {
    }

    #region IUIElement<SpellGem> Members

    public void Validate ( SpellGem val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        SpellGem el = new SpellGem( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }
    public void Copy ( SpellGem val ) {
      base.Copy( val );

      this.SpellIconOffsetX = val.SpellIconOffsetX ;
      this.SpellIconOffsetY = val.SpellIconOffsetY ;

      if( val.SpellGemDrawTemplate != null )
        this.SpellGemDrawTemplate = val.SpellGemDrawTemplate;

    }

    #endregion

    public SpellGemDrawTemplate SpellGemDrawTemplate {
      get {
        return ( SpellGemDrawTemplate ) this.GetElement( "SpellGemDrawTemplate" );
      }
      set {
        this.SpellGemDrawTemplate.Validate( value , "SpellGemDrawTemplate" );
      }
    }
    public int SpellIconOffsetX {
      get {
        return int.Parse( this.GetElement( "SpellIconOffsetX" ).InnerText );
      }
      set {
        this.Validate( "SpellIconOffsetX" , value.ToString() );
      }
    }
    public int SpellIconOffsetY {
      get {
        return int.Parse( this.GetElement( "SpellIconOffsetY" ).InnerText );
      }
      set {
        this.Validate( "SpellIconOffsetY" , value.ToString() );
      }
    }

  }
}
